package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Supplier;
import cn.wolfcode.crm.service.ISupplierService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("supplier")
public class SupplierController {
    @Autowired
    private ISupplierService supplierService;

    //查询所有供应商
    @RequestMapping("selectAll")
    @ResponseBody
    public List<Supplier> selectAll(){
        return supplierService.selectAll();
    }

    //只负责转发到供应商页面
    @RequestMapping("view")
    public String view() {
        return "supplier/supplier";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(Supplier supplier){
        try {
            supplierService.saveOrUpdate(supplier);
            return JSONResult.success("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.mark("保存失败");
        }
    }
    
    @RequestMapping("delete")
    @ResponseBody
    public Object delete( Long id) {
        supplierService.deleteByPrimaryKey(id);
        return new JSONResult();
    }
}
